home *** CD-ROM | disk | FTP | other *** search
- unit Editmenu;
- {$X+}
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, DBCtrls, StdCtrls, Mask, Grids, DBGrids, DB, DBTables,
- Menus, ClipBrd;
-
- type
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- Edit1: TMenuItem;
- Paste1: TMenuItem;
- Copy1: TMenuItem;
- Cut1: TMenuItem;
- Undo1: TMenuItem;
- Delete1: TMenuItem;
- DataSource1: TDataSource;
- Table1: TTable;
- DBGrid1: TDBGrid;
- Edit2: TEdit;
- DBEdit1: TDBEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Memo1: TMemo;
- Label4: TLabel;
- DBMemo1: TDBMemo;
- Label5: TLabel;
- N1: TMenuItem;
- procedure EditMenuClick(Sender: TObject);
- procedure MenuClick(Sender: TObject);
- private
- { This variable gets pre-set to nil (as do all others) }
- EditCtl: TCustomEdit;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.EditMenuClick(Sender: TObject);
- var
- Loop: Byte;
- begin
- EditCtl := nil;
- if ActiveControl is TCustomEdit then
- EditCtl := ActiveControl as TCustomEdit
- else
- { When editing in a grid, the grid is the active control, not the }
- { in-place editor, so we need to find the editor in the grid }
- if (ActiveControl is TCustomGrid) then
- with TCustomGrid(ActiveControl) do
- { If grid owns any controls, cycle through them checking for editor }
- if ControlCount > 0 then
- for Loop := 0 to Pred(ControlCount) do
- if Controls[Loop] is TInPlaceEdit then
- { Editor is visible when being used }
- if Controls[Loop].Visible then
- begin
- EditCtl := TInPlaceEdit(Controls[Loop]);
- Break;
- end;
- if Assigned(EditCtl) then
- begin
- Undo1.Enabled := Bool(EditCtl.Perform(em_CanUndo, 0, 0));
- Cut1.Enabled := EditCtl.SelLength > 0;
- Copy1.Enabled := Cut1.Enabled;
- Paste1.Enabled := ClipBoard.AsText <> '';
- Delete1.Enabled := EditCtl.SelLength > 0;
- end
- else
- begin
- Undo1.Enabled := False;
- Cut1.Enabled := False;
- Copy1.Enabled := False;
- Paste1.Enabled := False;
- Delete1.Enabled := False;
- end;
- end;
-
- procedure TForm1.MenuClick(Sender: TObject);
- begin
- if Assigned(EditCtl) then
- with EditCtl do
- case (Sender as TComponent).Tag of
- 1: Perform(em_Undo, 0, 0);
- 2: CutToClipBoard;
- 3: CopyToClipBoard;
- 4: PasteFromClipBoard;
- 5: ClearSelection;
- end;
- end;
-
- end.
-